/**
 * Created by kai on 2014/4/7.
 */

var bb = bb || {};


/**
 * 更换主题
 *
 * @author 孙宇
 * @requires jQuery,EasyUI
 * @param themeName
 */
bb.changeTheme = function(themeName) {
    //无themeName时,启用默认
    if(typeof themeName == "undefined" || themeName == "" )
    {
        themeName = "default"
    }
    var $easyuiTheme = $('#easyuiTheme');
    var url = $easyuiTheme.attr('href');
    var href = url.substring(0, url.indexOf('themes')) + 'themes/' + themeName + '/easyui.css';
    $easyuiTheme.attr('href', href);

    var $iframe = $('iframe');
    if ($iframe.length > 0) {
        for (var i = 0; i < $iframe.length; i++) {
            var ifr = $iframe[i];
            try {
                $(ifr).contents().find('#easyuiTheme').attr('href', href);
            } catch (e) {
                try {
                    ifr.contentWindow.document.getElementById('easyuiTheme').href = href;
                } catch (e) {
                }
            }
        }
    }
    $.cookie('easyuiTheme', themeName, { expires: 7 });
};


bb.addTab =function(id,title, url){
    if ($(id).tabs('exists', title)){
        $(id).tabs('select', title);
    } else {
        var content = '<iframe scrolling="auto" frameborder="0"  src="'+url+'" style="width:100%;height:100%;"></iframe>';
        $(id).tabs('add',{
            title:title,
            content:content,
            closable:true
        });
    }
}

/*网站加载执行方法*/
$(document).ready(function(){
    bb.changeTheme($.cookie('easyuiTheme'))
});